<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class PasswordAction extends BaseAccountAction {

	//修改密码
	public function index() {
		$this->init();
		$this->display();
	}

	//保存密码
	public function save() {
		$oldpassword = $_POST["oldpassword"];
		$password = $_POST["password"];
		$repassword = $_POST["repassword"];

		empty($oldpassword) && $this->ajaxReturn(null, array('oldpassword' => '请输入原密码'), -5);
		strlen($password) < 5 && $this->ajaxReturn(null, array('password' => '新密码长度必须大于 5 个字符!'), -1);
		$password != $repassword && $this->ajaxReturn(null, array('repassword' => '两次新密码不相同!'), -2);

		$User = D('User')->where("user_id=" . $this->uid);
		$_oldpassword = $User->getField("password");
		empty($_oldpassword) && $this->error("账号不存在");
		md5($oldpassword) != $_oldpassword && $this->ajaxReturn(null, array('oldpassword' => '老密码不正确!'), -3);
		//修改密码
		$User->user_id = $this->uid;
		$User->password = md5($password);
		$User->save();
		$this->ajaxReturn(null, '修改成功!', 1);
	}

}

?>
